JBoss Community Archive (Read Only)

Graphene 2

Page Extensions

The Page Extensions SPI is not yet available for public use, we discourage to use it yet

Page extensions mechanism provides a way to easily install your JavaScript code into the page. Page extensions are used mainly in cooperation with JavaScript Interface, but they can be used independently too.

Basic Usage

Own Extensions

Extensions has to implement PageExtension interface to define:

  • name,

  • JavaScript code to be executed when the extension is installed,

  • JavaScript code returning true if the extension is already installed, false otherwise,

  • dependencies.

SPI

To provide your own extensions you can use PageExtensionProvider service containg the following method:

// returns a list of extension for the given test class
List<PageExtension> getPageExtensions(TestClass testClass);

Registry

The second way to provide your own extension is to use PageExtensionRegistry:

PageExtension pageExtension = new MyCoolPageExtension(...);
GraphenePageExtensionsContext.getRegistryProxy().register(pageExtension);

The registry can be also used to check whether the given extension is available:

// returns page extension with the given name, or null if there is no extension with the given name
GraphenePageExtensionsContext.getRegistryProxy().getExtension("my cool extension");

Installation

Each extensions is defined with its name. When you want to install the extension just ask for its installator and install it. All defined dependencies will be installed too. When the extension is detected as already installed, the installation is skipped (including installation of all dependencies).

GraphenePageExtensionsContext.getInstallatorProviderProxy().installator("extension name").install();

The installator is available only for extensions already registered via SPI or registry.

When a page is reloaded, all injected JavaScript code is lost, so the extension has to be installed again.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:14:40 UTC, last content change 2013-09-11 09:47:52 UTC.